#include "StdAfx.h"
#include "GameBase.h"
#include "SubStructure.h"
#include "Scenemanager.h"

Scenemanager* Scenemanager::Instance()
{
	if(thispointer == NULL)
	{
		thispointer = new Scenemanager();
	}
	return thispointer;
}

VOID Scenemanager::Init()
{
	gameScene = new GameScene();
	sysScene = new SysScene();
	sysScene->Init();
	gameScene->EventReceiver(this);
	sysScene->EventReceiver(this);
}

VOID Scenemanager::Run()
{
	KeyboardSet->VDOWN = GetAsyncKeyState(VK_DOWN);
	KeyboardSet->VUP = GetAsyncKeyState(VK_UP);
	KeyboardSet->VLEFT = GetAsyncKeyState(VK_LEFT);
	KeyboardSet->VRIGHT = GetAsyncKeyState(VK_RIGHT);
	KeyboardSet->V_ESC = GetAsyncKeyState(VK_ESCAPE);
	KeyboardSet->V_Z = GetAsyncKeyState(0x5A);
	KeyboardSet->V_X = GetAsyncKeyState(0x58);
	KeyboardSet->V_SHIFT = GetAsyncKeyState(VK_SHIFT);
	KeyboardSet->V_CTRL = GetAsyncKeyState(VK_CONTROL);
	if(managerState == SYSSCENE)
	{
		sysScene->Update(KeyboardSet);
	}
	else if(managerState == GAMESCENE)
	{
		gameScene->Update(KeyboardSet);
	}
	else if(managerState == CLOSINGSCENE)
	{
		closingScene->Update(KeyboardSet);
	}
}

VOID Scenemanager::Draw()
{
	if(managerState == SYSSCENE)
	{
		sysScene->Draw();
	}
	else if(managerState == GAMESCENE)
	{
		gameScene->Draw();
	}
	else if(managerState == CLOSINGSCENE)
	{
		closingScene->Draw();
	}
}

VOID Scenemanager::OnEvent(GameBase* pObj, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	if(uMsg == GAMESCENE)
	{
		managerState = GAMESCENE;
		gameScene->Reset();
		gameScene->MakeChar(wParam >> 4);
		gameScene->MakeStage(wParam & 15);
	}
	if(uMsg == SYSSCENE)
	{
		managerState = SYSSCENE;
		sysScene->Reset();
	}
	if(uMsg == CLOSINGSCENE)
	{
		managerState = CLOSINGSCENE;
		closingScene->Reset();
	}
}

Scenemanager::Scenemanager()
{
	gameScene = NULL;
	sysScene = NULL;
	closingScene = NULL;
	KeyboardSet = new KeyInput;

	managerState = 0;
}